package TestThread;

import java.util.Scanner;

public class demo1 {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            Thread cur = Thread.currentThread();
            while (!cur.isInterrupted()) {
                System.out.println("线程运行中...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("线程已退出");
        });
        System.out.println(t.getState());
        t.start();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入整数，0表示线程终止：");
        int n = scanner.nextInt();
        if(n == 0) {
            t.interrupt();
        }
    }
}
